function trim(val)
 { 
	return val.replace(/(\s*$)/g, "");  
}

window.onload  = function(){	
var exp = document.getElementById("ship_way");

	if( !exp && typeof(exp)!="undefined" && exp!=0 ){

	} else {
		var ship_way_value = exp.value;
			if(ship_way_value == '0'){
				document.getElementById("ship_way_hidden").style.display="";
			}else{
				document.getElementById("ship_way_hidden").style.display="none";
			}
		}	
	}

function searcher(){

   var start_attr=""; 
  if(document.getElementById("startprovince").value!="")
  {
      start_attr = document.getElementById("startprovince").value+"|"; 
  }

  if(document.getElementById("starteparchy_code").value!="")
  {
      start_attr += document.getElementById("starteparchy_code").value+"|"; 
  }

  if(document.getElementById("startcity_code").value!="")
  {
      start_attr += document.getElementById("startcity_code").value+"|"; 
  }
  
  var end_attr=""; 
  if(document.getElementById("endprovince").value!="")
  {
      end_attr = document.getElementById("endprovince").value+"|"; 
  }

  if(document.getElementById("endeparchy_code").value!="")
  {
      end_attr += document.getElementById("endeparchy_code").value+"|"; 
  }

  if(document.getElementById("endcity_code").value!="")
  {
      end_attr += document.getElementById("endcity_code").value+"|"; 
  }
  
  document.getElementById("end_addr").value = end_attr;
  document.getElementById("start_addr").value = start_attr;
  
	document.indexForm.submit();
}	
	
function ship_way_change(val){
	if(val == '0'){
		document.getElementById("ship_way_hidden").style.display="";
	}else{
		document.getElementById("ship_way_hidden").style.display="none";
	}
}

function submitForm(){
	var ship_way_value = document.getElementById("ship_way").value;
		if(ship_way_value != '0'){
			document.getElementById("car_type").value="";
			document.getElementById("app_weight").value="";
			document.getElementById("act_weight").value="";
			document.getElementById("car_long").value="";
		}
		var area_attr_str = '';
		if(document.getElementById('startprovince').value!=''){		
		area_attr_str += document.getElementById('startprovince').value+'|';
		if(document.getElementById('starteparchy_code').value!=''){
			area_attr_str += document.getElementById('starteparchy_code').value+'|';
			if(document.getElementById('startcity_code').value!=''){
				area_attr_str += document.getElementById('startcity_code').value+'|';
			}
		 }
		}
		if(area_attr_str==''){
			area_attr_str = document.getElementById('start_addr_bak').value;
		}
		if(area_attr_str == ''){
			alert('请选择出发地点');
			return;
		}
		document.getElementById('start_addr').value = area_attr_str;

	
	var area_attr_end = '';		
	if(document.getElementById('endprovince').value!=''){
		area_attr_end += document.getElementById('endprovince').value+'|';
		if(document.getElementById('endeparchy_code').value!=''){
			area_attr_end += document.getElementById('endeparchy_code').value+'|';
			if(document.getElementById('endcity_code').value!=''){
				area_attr_end += document.getElementById('endcity_code').value+'|';
			}
		  }
		}
		if(area_attr_end==''){
			area_attr_end = document.getElementById('end_addr_bak').value;
		}
		if(area_attr_end == ''){
			alert('请选择目的地');
			return;
		}
		document.getElementById('end_addr').value = area_attr_end;
	
	if(document.getElementById('ship_type').value==""){

				alert('请输入运输方式');

				document.getElementById('ship_type').focus();

				return false;

			}
			if(document.getElementById('ship_way').value==""){

				alert('请输入运输类型');

				document.getElementById('ship_way').focus();

				return false;

			}
			
	  if(document.getElementById('send_price').value==""){

				alert('请输入运输价格');

				document.getElementById('send_price').focus();

				return false;

			}
			if(document.getElementById('mileage').value==""){

				alert('请输入公里数');

				document.getElementById('mileage').focus();

				return false;

			}
	if(document.getElementById('contact').value==""){

				alert('请输入联系人');

				document.getElementById('contact').focus();

				return false;

	}	
	var cellphone = document.getElementById('cellphone');
	if(cellphone ==""){
		alert('请输入手机号码！');
		return false;
	}else {
	var mobileReg = /^(((13[0-9]{1})|159|153)+\d{8})$/; 
	if(!mobileReg.test(trim(document.getElementById('cellphone').value))){
      alert('请输入有效的手机号码！');
	  document.getElementById('cellphone').focus();
      return; 		
	}
  }
	document.addForm.submit();
}


function ChangeAreaStyleS(){
	document.getElementById("start_addr").value = '';
	document.getElementById("areaId1").style.display = 'none';
	document.getElementById("areaId2").style.display = 'block';
}
function ChangeAreaStyleE(){
	document.getElementById("end_addr").value = '';
	document.getElementById("areaId3").style.display = 'none';
	document.getElementById("areaId4").style.display = 'block';
}


function setstartProvince()
{
	Ts_areaInfo.getAreaClassByUpId('000000000000000',function(data){
		DWRUtil.removeAllOptions('startprovince');
		DWRUtil.addOptions('startprovince',{'':'请选择'});
		DWRUtil.addOptions('startprovince',data);
	})
}


function setendProvince()
{
	Ts_areaInfo.getAreaClassByUpId('000000000000000',function(data){
		DWRUtil.removeAllOptions('endprovince');
		DWRUtil.addOptions('endprovince',{'':'请选择'});
		DWRUtil.addOptions('endprovince',data);
	})
}
function setCitys(prov,val)
{var provence=prov;
	 Ts_areaInfo.getAreaClassByUpId(provence,function(data){
		DWRUtil.removeAllOptions(val+'eparchy_code');
		DWRUtil.addOptions(val+'eparchy_code',{'':'请选择'});
		DWRUtil.addOptions(val+'eparchy_code',data);
		DWRUtil.removeAllOptions(val+'city_code');
		DWRUtil.addOptions(val+'city_code',{'':'请选择'});
	});
}

function setAreas(city_id,val){
	Ts_areaInfo.getAreaClassByUpId(city_id,function(data){
	 	DWRUtil.removeAllOptions(val+'city_code');
		DWRUtil.addOptions(val+'city_code',{'':'请选择'});
	 	DWRUtil.addOptions(val+'city_code',data);
	});
}